package com.bear.newsset.dao.entity;

import com.bear.newsset.dao.DaoSession;
import com.bear.newsset.dao.ImageSqlEntityDao;
import com.bear.newsset.dao.NewsDataSqlEntityDao;
import com.bear.newsset.dao.StringMapSqlEntityDao;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinProperty;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Unique;

import java.util.List;

/**
 * 新闻数据实体类    SQL Entity
 */
@Entity
public class NewsDataSqlEntity {
    @Id(autoincrement = true)
    private Long id;                                //Id
    private Long queryId;                           //查询Id，用于查询多条新闻
    @Unique
    private String newsId;                          //新闻唯一Id
    /** {@link com.bear.newsset.util.NewsItemType} **/
    private int itemType;                           //item类型。新闻图片的数量
    private String title;                           //新闻标题
    private String url;                             //详细新闻链接
    @ToMany(joinProperties = {@JoinProperty(name = "newsId", referencedName = "newsId")})
    private List<ImageSqlEntity> imageUrlList;      //图片集链接
    private String mainLable;                       //主标签
    private String childLable;                      //子标签
    private String appCode;                         //网址名称  eg:腾讯
    private String sourceRegion;                    //数据源地区
    private int publishDate;                        //发布时间戳  eg:1530343320
    @ToMany(joinProperties = {@JoinProperty(name = "newsId", referencedName = "onlyId")})
    private List<StringMapSqlEntity> entitiesList;  //识别的实体名

    @Override
    public String toString() {
        return "NewsDataSqlEntity{" +
                "id=" + id +
                ", queryId=" + queryId +
                ", newsId='" + newsId + '\'' +
                ", itemType=" + itemType +
                ", title='" + title + '\'' +
                ", url='" + url + '\'' +
                ", imageUrlListSize=" + (imageUrlList != null ? imageUrlList.size() : -1) +
                ", mainLable='" + mainLable + '\'' +
                ", childLable='" + childLable + '\'' +
                ", appCode='" + appCode + '\'' +
                ", sourceRegion='" + sourceRegion + '\'' +
                ", publishDate=" + publishDate +
                ", entitiesListSize=" + (entitiesList != null ? entitiesList.size() : -1) +
                ", daoSession=" + daoSession +
                ", myDao=" + myDao +
                '}';
    }

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 1362002043)
    private transient NewsDataSqlEntityDao myDao;
    @Generated(hash = 1293607114)
    public NewsDataSqlEntity(Long id, Long queryId, String newsId, int itemType,
            String title, String url, String mainLable, String childLable,
            String appCode, String sourceRegion, int publishDate) {
        this.id = id;
        this.queryId = queryId;
        this.newsId = newsId;
        this.itemType = itemType;
        this.title = title;
        this.url = url;
        this.mainLable = mainLable;
        this.childLable = childLable;
        this.appCode = appCode;
        this.sourceRegion = sourceRegion;
        this.publishDate = publishDate;
    }
    @Generated(hash = 1401910784)
    public NewsDataSqlEntity() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Long getQueryId() {
        return this.queryId;
    }
    public void setQueryId(Long queryId) {
        this.queryId = queryId;
    }
    public String getNewsId() {
        return this.newsId;
    }
    public void setNewsId(String newsId) {
        this.newsId = newsId;
    }
    public int getItemType() {
        return this.itemType;
    }
    public void setItemType(int itemType) {
        this.itemType = itemType;
    }
    public String getTitle() {
        return this.title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getUrl() {
        return this.url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getMainLable() {
        return this.mainLable;
    }
    public void setMainLable(String mainLable) {
        this.mainLable = mainLable;
    }
    public String getChildLable() {
        return this.childLable;
    }
    public void setChildLable(String childLable) {
        this.childLable = childLable;
    }
    public String getAppCode() {
        return this.appCode;
    }
    public void setAppCode(String appCode) {
        this.appCode = appCode;
    }
    public String getSourceRegion() {
        return this.sourceRegion;
    }
    public void setSourceRegion(String sourceRegion) {
        this.sourceRegion = sourceRegion;
    }
    public int getPublishDate() {
        return this.publishDate;
    }
    public void setPublishDate(int publishDate) {
        this.publishDate = publishDate;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1389162937)
    public List<ImageSqlEntity> getImageUrlList() {
        if (imageUrlList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            ImageSqlEntityDao targetDao = daoSession.getImageSqlEntityDao();
            List<ImageSqlEntity> imageUrlListNew = targetDao
                    ._queryNewsDataSqlEntity_ImageUrlList(newsId);
            synchronized (this) {
                if (imageUrlList == null) {
                    imageUrlList = imageUrlListNew;
                }
            }
        }
        return imageUrlList;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 925432245)
    public synchronized void resetImageUrlList() {
        imageUrlList = null;
    }
    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1293232999)
    public List<StringMapSqlEntity> getEntitiesList() {
        if (entitiesList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            StringMapSqlEntityDao targetDao = daoSession.getStringMapSqlEntityDao();
            List<StringMapSqlEntity> entitiesListNew = targetDao
                    ._queryNewsDataSqlEntity_EntitiesList(newsId);
            synchronized (this) {
                if (entitiesList == null) {
                    entitiesList = entitiesListNew;
                }
            }
        }
        return entitiesList;
    }
    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 784710756)
    public synchronized void resetEntitiesList() {
        entitiesList = null;
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }
    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }
    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 957243528)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getNewsDataSqlEntityDao() : null;
    }
}
